<template>
  <div class="search">
    <f-drawer :visible="drawerVisible" :title="modalTitle" ref="topicDrawer" width="60%" @submit="handleSubmit" @visibleChange="visibleChange">
      <a-tabs @tabClick="handleTabClick" :defaultActiveKey="current" v-model="current">
        <a-tab-pane tab="订单信息" key="form1">
          <order-form ref="form1"></order-form>
        </a-tab-pane>
        <a-tab-pane tab="发货信息" key="form2" v-if="[20, 21, 3, 5].includes(formData.orderState)">
          <order-logistics ref="form2"></order-logistics>
        </a-tab-pane>
        <a-tab-pane tab="物流跟踪" key="form3" v-if="[21, 3, 5].includes(formData.orderState)">
          <order-logistics-progress ref="form3"></order-logistics-progress>
        </a-tab-pane>
      </a-tabs>
    </f-drawer>
  </div>
</template>
<script>

  import OrderForm from './order_form'
  import OrderLogistics from './order_logistics'
  import OrderLogisticsProgress from './order_logistics_progress'

  export default {
    name: 'OrderDrawer',
    props: {},
    data() {
      return {
        saving: false,
        isEdit: false,
        drawerVisible: false,
        title: '',
        current: 'form1',
        formData: {
          orderId: '',
          orderState: 0
        },
        forms: [
          'form1',
          'form2',
          'form3'
        ]
      }
    },
    methods: {
      handleShow(data) {
        if (data && data.companyId) {
          this.isEdit = true
          this.formData = data
        } else {
          this.formData = {}
        }
        this.$refs.topicDrawer.show()
        this.handleTabClick('form1')
      },
      visibleChange(drawerVisible) {
        this.drawerVisible = drawerVisible
      },
      handleSubmit(callback) {
        this.$refs[this.current].handleSubmit(callback)
      },
      handleTabClick(name) {
        this.current = name
        if (this.current === this.forms[0]) {
          this.title = '订单编号：' + this.formData.orderNo
        }
        this.$nextTick(() => {
          this.$refs[this.current].setData(this.formData)
        })
      }
    },
    computed: {
      modalTitle: function() {
        return this.title
      }
    },
    created() {

    },
    components: { OrderLogisticsProgress, OrderLogistics, OrderForm }
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
